<?php

namespace Crc\Entity;

use Doctrine\ORM\Mapping AS ORM,
    Doctrine\Common\Annotations\AnnotationRegistry,
    Doctrine\Common\Collections;

/**
 *
 *
 * @ORM\Entity
 * @ORM\Table(name="acl_resource")
 */

class AclResource
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue
     * @var int
     */
    private $id;

    /**
     * @ORM\ManyToOne(targetEntity="AclResource", inversedBy="children")
     * @ORM\JoinColumn(name="id_parent", referencedColumnName="id")
     */
    private $parent;

     /**
     * @ORM\OneToMany(targetEntity="AclResource", mappedBy="parent")
     */
    private $children;

    /**
     * @ORM\OneToMany(targetEntity="AclRight", mappedBy="resource")
     */
    private $rights;

    /**
     * @ORM\Column(type="string")
     */
    private $resource;

    /**
     * @ORM\Column(type="string")
     */
    private $description;

    public function __construct()
    {
        $this->children = new ArrayCollection();
        $this->rights = new ArrayCollection();
    }

    public function setId($_id)
    {
        $this->id = $_id;
        return $this;
    }

    public function getId()
    {
        return $this->id;
    }

    public function addChild(AclResource $_child) {
        $this->children->add($_child);
        $_child->setParent($this);
        return $this;
    }

    public function getChildren()
    {
        return $this->children;
    }

    public function setParent(AclResource $_parent = null)
    {
        $this->parent = $_parent;
        return $this;
    }

    public function getParent()
    {
        return $this->parent;
    }

    public function addRights(AclRight $_right)
    {
        $this->rights->add($_right);
        $_right->setResource($this);
        return $this;
    }

    public function getRights()
    {
        return $this->rights;
    }

    public function setResource($_resource)
    {
        $this->resource = $_resource;
        return $this;
    }

    public function getResource()
    {
        return $this->resource;
    }

    public function setDescription($_description)
    {
        $this->description = $_description;
        return $this;
    }

    public function getDescription()
    {
        return $this->description;
    }
}